package com.controller.xsxt;

import com.entity.common.ApiResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.xsxt.TestService;
import com.entity.xsxt.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by System on 2019/03/19 11:43:59.
 */
@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    private TestService testService;

    @RequestMapping("/getPageList")
    public Map<String,Object> getPageList(@RequestParam(value = "pager.pageNo",defaultValue ="1" )  Integer pageNum,
                @RequestParam(value = "pager.pageSize",defaultValue ="10" ) Integer pageSize,Test test){
        Map<String, Object> map=new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Test> pageInfo = new PageInfo<>(testService.getPageList(test));
        map.put("rows",pageInfo.getList());
        map.put("pager.totalRows", pageInfo.getTotal());
        map.put("pager.pageNo",pageNum);
        return  map;
    }

    @RequestMapping("/addTest")
    public ApiResult addTest(Test test){
        return testService.addTest(test);
    }

    @RequestMapping("/deleteTest")
    public ApiResult deleteTest(int id){
        return testService.deleteTest(id);
    }

    @RequestMapping("/getTestById")
    public ApiResult getTestById(Integer id){
        return testService.getTestById(id);
    }

    @RequestMapping("/editTest")
    public ApiResult editTest(Test test){
        return testService.editTest(test);
    }

}
